﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xenta.Operations;
using Xenta.Utils;

namespace Xenta.Tests.Operations
{
    [TestFixture]
    public class CatalogItemTranslationTests : OperationTest
    {
        protected override IEnumerable<Type> ModelMappings
        {
            get
            {
                return NHMappings.ALL;
            }
        }

        [TestCase("name", "shortDescription", "description")]
        public void Can_CRUD(string name, string shortDescription, string description)
        {
            var t_item = Processor.Execute(new CreateCatalogItemTranslation
            {
                HolderID = Processor.Execute(new CreateCatalogItem
                {
                    SupplierID = Processor.Execute(new CreateCatalogSupplier()).Result.EntityID,
                }).Result.EntityID,
                LanguageID = Processor.Execute(new CreateLanguage
                {
                    Code = "xy"
                }).Result.EntityID,
                Name = name,
                ShortDescription = shortDescription,
                Description = description
            }).Result;

            Assert.NotNull(t_item);
            t_item.Name.AreEqualIgnoringCase(name);
            t_item.ShortDescription.AreEqualIgnoringCase(shortDescription);
            t_item.Description.AreEqualIgnoringCase(description);
            t_item.AreEqual(Processor.Execute(new GetCatalogItemTranslation
            {
                EntityID = t_item.EntityID
            }).Result);


            name = name.Reverse();
            shortDescription = shortDescription.Reverse();
            description = description.Reverse();
            var upd_t_item = Processor.Execute(new UpdateCatalogItemTranslation
            {
                EntityID = t_item.EntityID,
                LanguageID = t_item.Language.EntityID,
                Name = name,
                ShortDescription = shortDescription,
                Description = description
            }).Result;

            Assert.NotNull(upd_t_item);
            upd_t_item.AreEqual(t_item);
            upd_t_item.Name.AreEqualIgnoringCase(name);
            upd_t_item.ShortDescription.AreEqualIgnoringCase(shortDescription);
            upd_t_item.Description.AreEqualIgnoringCase(description);

            Processor.Execute(new DeleteCatalogItemTranslation
            {
                EntityID = t_item.EntityID
            });
        }
    }
}
